<template>
	<view class="content poRel">
		<view class="wid100 bacFFF">
			<view class="wid100 dis disAl" style="height: 80rpx;">
				<view class="wid90 mar dis disAl disJuC borRad40 hei60" style="background: #E5E5E5;">
					<view class="dis disJuC" style="width: 13%;">
						<uni-icons type="search" size="30rpx" color="#AFB6B1"></uni-icons>
					</view>
					<input class="wid85 foSi20" v-model="sousuo" @input="sousuoInput" placeholder="请输入系统订单号查询"
						placeholder-style="color: #AFB6B1;" />
				</view>
			</view>
			<view class="wid87 mar dis disJuB hei86 foSi25 fowe800 ">
				<view class="dis disAl hei80" @click="xuanClick(6)"
					:style="xuan == 6?'border-bottom: 4rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 4rpx solid #fff;color: #585858;'">
					全部</view>
				<view class="dis disAl hei80" @click="xuanClick(7)"
					:style="xuan == 7?'border-bottom: 4rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 4rpx solid #fff;color: #585858;'">
					申请中</view>
				<view class="dis disAl hei80" @click="xuanClick(8)"
					:style="xuan == 8?'border-bottom: 4rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 4rpx solid #fff;color: #585858;'">
					同意退款</view>
				<view class="dis disAl hei80" @click="xuanClick(9)"
					:style="xuan == 9?'border-bottom: 4rpx solid '+theme.main_color+';color: '+theme.main_color+';':'border-bottom: 4rpx solid #fff;color: #585858;'">
					拒绝退款</view>
			</view>
		</view>
		<scroll-view style="height: calc(100vh - 196rpx);" class="wid100" scroll-y="true" @scrolltolower="lower">
			<view style="height: 1rpx;"></view>
			<view v-if="list.length == 0" class="wid90 mar fowe800 foSi35">
				<view style="height: 50rpx;"></view>
				<view class="dis disJuC">
					<image src="../../static/zanwu2.png" style="width: 400rpx;height: 300rpx;"></image>
				</view>
				<view class="textCen mar-top20" style="color: #868686;">暂无数据</view>
			</view>
			<block v-for="(item,index) in list" :key="index">
				<view class="mar-top20 wid90 mar bacFFF borRad20">
					<view class="wid90 mar">
						<view class="hei80 dis disAl disJuB">
							<view class="foSi20" style="color: #5B5B5B;">订单号：{{item.order_id}}</view>
							<view class="foSi25 fowe800">
								<span :style="'color: '+theme.main_color+';'"
									v-if="item.pay_refund_status == 1">申请中</span>
								<span :style="'color: '+theme.main_color+';'"
									v-if="item.pay_refund_status == 2">已通过</span>
								<span :style="'color: '+theme.main_color+';'"
									v-if="item.pay_refund_status == 3">已驳回</span>

								<!-- <span v-if="" style="color: #00AD27;"></span>
								<span v-if="" style="color: #FF0000;"></span>
								<span v-if=""></span> -->
							</view>
						</view>
						<view class="xia"></view>
						<view class="dis disAl wid100 mar-top30">
							<view class="wid25" style="height: 142rpx;">
								<image :src="item.cover_img" class="hei100 borRad10" style="width: 142rpx;">
								</image>
							</view>
							<view style="width: 75%;">
								<view class="dis disAl disJuB">
									<view class="foSi30 fowe800" style="line-height: 40rpx;">{{item.service.name}}
									</view>
									<view class="foSi25">×1</view>
								</view>
								<view class="foSi20" style="color: #878787;">
									<view class=" mar-top10">服务技师：{{item.tech_name}}</view>
									<view class=" mar-top10">预约时间：{{item.start_time}}</view>
									<view class=" mar-top10">
										<span>总计：</span>
										<span class="foSi25" style="color: #FF0000;">¥{{item.total_price}}</span>
									</view>
								</view>

							</view>

						</view>
						<view class="tkly">
							申请退款理由：{{item.pay_refund_apply}}
						</view>
						<view class="mar-top20 dis foSi20 wid100" style="justify-content: flex-end;">
							<view class="dis disAl disJuC mar-right20 butt1" v-if="item.pay_refund_status == 1"
								@click="outorder(index,3)">拒绝退款</view>
							<view class="dis disAl disJuC coFFF butt2" v-if="item.pay_refund_status == 1"
								@click="outorder(index,2)"
								:style="'background-color: '+theme.main_color+';border: 1rpx solid '+theme.main_color+';'">
								同意退款</view>
						</view>
						<view style="height: 30rpx;"></view>
					</view>
				</view>
			</block>
			<view style="height: 50rpx;"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				xuan: 6,
				ty: 0,
				timer: null,
				sousuo: '',
				last_page: 0,
				page: 1,
				list: [],
				theme: null
			}
		},
		onLoad(option) {
			this.theme = uni.getStorageSync('theme')
			this.ty = option.ty
			this.getList()
		},
		methods: {
			outorder(index, status) {
				let that = this
				let row = that.list[index]
				if (status == 3) {
					// 拒绝退款
					uni.showModal({
						title: '请输入拒绝理由',
						content: '',
						editable: true, //是否显示输入框
						placeholderText: '请输入拒绝理由', //输入框提示内容
						confirmText: '确认',
						cancelText: '取消',
						success: (res) => {
							if (res.confirm) {
								let reason = res.content;
								
								uni.showLoading({
									title: '加载中...'
								})
								uni.request({
									url: that.global.url + 'api/qianyu_smfw/agent/out_order_check',
									method: "POST",
									header: {
										'site-id': that.global.site_id, //自定义请求头信息
										'token': uni.getStorageSync('token')
									},
									data: {
										agent_id: uni.getStorageSync('agent_id'),
										orderid: row.id,
										status:status,
										reason:reason
									},
									success(res) {
										let result = res.data
										console.log(result.data)
										if (result.code == 1) {
											// that.agent_info = result.data
											that.list[index]['pay_refund_status'] = status
										} else {
											uni.showToast({
												title: result.msg,
												//将值设置为 success 或者直接不用写icon这个参数
												icon: 'error',
												//显示持续时间为 2秒
												duration: 2000
											})
										}
									},
									complete() {
										uni.hideLoading()
									}
								})


								
							}
						}
					});
				}else{
					// 同意退款
					uni.showModal({
						title: '提示',
						// 提示文字
						content: '确认同意退款吗？退款后将取消该订单',
						// 取消按钮的文字自定义
						cancelText: "取消",
						// 确认按钮的文字自定义
						confirmText: "确认退款",
						//删除字体的颜色
						confirmColor: 'red',
						//取消字体的颜色
						cancelColor: '#000000',
						success: function(res) {
							if (res.confirm) {
								// 执行确认后的操作
								uni.showLoading({
									title: '加载中...'
								})
								uni.request({
									url: that.global.url + 'api/qianyu_smfw/agent/out_order_check',
									method: "POST",
									header: {
										'site-id': that.global.site_id, //自定义请求头信息
										'token': uni.getStorageSync('token')
									},
									data: {
										agent_id: uni.getStorageSync('agent_id'),
										orderid: row.id,
										status:status,
										reason:''
									},
									success(res) {
										let result = res.data
										console.log(result.data)
										if (result.code == 1) {
											// that.agent_info = result.data
											that.list[index]['pay_refund_status'] = status
										} else {
											uni.showToast({
												title: result.msg,
												//将值设置为 success 或者直接不用写icon这个参数
												icon: 'error',
												//显示持续时间为 2秒
												duration: 2000
											})
										}
									},
									complete() {
										uni.hideLoading()
									}
								})
								
							}
						}
					})
				}
			},
			xuanClick(index) {
				if (this.xuan != index) {
					this.xuan = index
					this.page = 1
					this.list = []
					this.getList()
				}

			},
			sousuoInput: function(event) {
				var that = this
				if (that.timer !== null) clearTimeout(that.timer)
				that.timer = setTimeout(() => {
					that.sousuo = event.target.value
					this.page = 1
					this.list = []
					this.getList()
					console.log(that.sousuo)
				}, 1000)
			},
			lower(e) {
				if (this.last_page > this.page) {
					this.page++
					this.getList()
				}
			},
			getList() {
				let that = this
				uni.showLoading({
					title: '加载中...'
				})
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/agent/order_list',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						agent_id: uni.getStorageSync('agent_id'),
						service_status: that.xuan,
						keyword: that.sousuo,
						ordertype: that.ty == 1 ? 2 : 1,

					},
					success(res) {
						let result = res.data
						console.log(result.data)
						if (result.code == 1) {
							// that.agent_info = result.data
							that.list = that.list.concat(result.data.data)
							that.last_page = result.data.last_page
						} else {
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							})
						}
					},
					complete() {
						uni.hideLoading()
					}
				})
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
		background-color: #F3F1F1;
	}

	.xia {
		height: 1rpx;
		background-color: #E5E5E5;
	}

	.butt1 {
		width: 120rpx;
		height: 40rpx;
		color: #414040;
		border: 1rpx solid #414141;
		border-radius: 8rpx;
	}

	.butt2 {
		width: 120rpx;
		height: 40rpx;
		border-radius: 8rpx;
	}

	.tkly {
		margin-top: 5px;
		margin-bottom: 5px;
		color: #555;
		font-size: 14px;
	}
</style>